// src/main/java/com/training/service/TeacherService.java

package com.training.service;

import com.training.entity.User;
import com.training.entity.Teacher; // 确保导入 Teacher 实体
import com.training.mapper.UserMapper;
import com.training.mapper.TeacherMapper; // 确保导入 TeacherMapper

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TeacherService {

    private final UserMapper userMapper;
    private final TeacherMapper teacherMapper;

    @Autowired
    public TeacherService(UserMapper userMapper, TeacherMapper teacherMapper) {
        this.userMapper = userMapper;
        this.teacherMapper = teacherMapper;
    }

    public User getUserById(Long userId) {
        return userMapper.findUserById(userId);
    }

    /**
     * Get Teacher ID by User ID.
     * Assumes there's a way to link a User to a Teacher (e.g., Teacher entity has a userId field).
     * @param userId The ID of the User associated with the Teacher.
     * @return The Teacher's ID, or null if no corresponding Teacher is found.
     */
    public Long getTeacherIdByUserId(Long userId) {
        Teacher teacher = teacherMapper.findByUserId(userId); // 假设 TeacherMapper 有 findByUserId 方法
        return teacher != null ? teacher.getId() : null;
    }

    /**
     * NEW: Get Teacher entity by User ID.
     * This method is added to resolve the "cannot resolve method 'getTeacherByUserId'" error.
     * @param userId The ID of the User associated with the Teacher.
     * @return The Teacher object, or null if no corresponding Teacher is found.
     */
    public Teacher getTeacherByUserId(Long userId) {
        return teacherMapper.findByUserId(userId); // 同样假设 TeacherMapper 有 findByUserId 方法
    }
}